from pptx import Presentation
from pptx.chart.data import CategoryChartData, ChartData


def page1():
    slide = slides[0]
    shape1 = slide.shapes[0]
    tf = shape1.text_frame
    tf.paragraphs[0].runs[0].text = '这是测试报表'
    shape2 = slide.shapes[1]
    tf = shape2.text_frame
    tf.paragraphs[0].runs[1].text = '2020-8-8'

def page2():
    slide = slides[1]
    #设置净值
    slide.shapes[2].text_frame.paragraphs[0].runs[0].text = "95678.99"
    #设置描述
    slide.shapes[6].text_frame.paragraphs[0].runs[0].text = "新的描述如下..."
    table = slide.shapes[3].table
    for i in range(1, 7):
        table.cell(i, 0).text = '2020-4-38'
        table.cell(i, 1).text = '3456.88'
        table.cell(i, 2).text = '456.88'

    #添加折线图
    chart = slide.shapes[5].chart
    chart_data = ChartData()
    chart_data.categories = ['West', 'East', 'North', 'South', 'Other']
    chart_data.add_series('Series 1', (0.135, 0.324, 0.180, 0.235, 0.126))
    chart.replace_data(chart_data)

def page3():
    slide = slides[2]
    #重仓股
    table = slide.shapes[1].table
    for i in range(1, 11):
        table.cell(i, 0).text = 'BABA'
        table.cell(i, 1).text = '3456.88'
        table.cell(i, 2).text = '456.88'    
    #资产类别
    table = slide.shapes[4].table
    for i in range(1, 5):
        table.cell(i, 0).text = '股票'
        table.cell(i, 1).text = '20'
    #资产饼图
    chart = slide.shapes[5].chart
    chart_data = ChartData()
    chart_data.categories = ['权益类', '债券类', '货币类', '其他']
    chart_data.add_series('Series 1', (0.261, 0.324, 0.180, 0.235))
    chart.replace_data(chart_data) 

def page4():
    text = '''
    这是第一段

    这是第二段
    '''
    slide = slides[3]
    shape = slide.shapes[1]
    tf = shape.text_frame
    tf.text = text

ppt = Presentation('客户报表.pptx')
slides = ppt.slides
# page1()
# page2()
# page3()
page4()
ppt.save('张三.pptx')

    

